<%@ page language="java" %>
<%@ page pageEncoding="UTF-8" %>
<%@ page contentType="text/html;charset=UTF-8" %>

<%
    // application.setAttribute( "nickname" , "今晚打老虎" );
    pageContext.setAttribute( "nickname" , "今晚打老虎" , PageContext.APPLICATION_SCOPE );
    // session.setAttribute( "nickname" , "拐角遇到猪" );
    pageContext.setAttribute( "nickname" , "拐角遇到猪" , PageContext.SESSION_SCOPE );
    // request.setAttribute( "nickname" , "上课打瞌睡" );
    pageContext.setAttribute( "nickname" , "上课打瞌睡" , PageContext.REQUEST_SCOPE );
    // pageContext.setAttribute( "nickname" , "明早吃肘子" );
    pageContext.setAttribute( "nickname" , "明早吃肘子" , PageContext.PAGE_SCOPE );
%>


<html>
    <head>
        <title>属性操作</title>
    </head>
    <body>

    <h3 align="center">从不同作用域中获取属性值</h3>

    <table align="center" border="1">
        <tr>
            <td>application attribute</td>
            <td><%= application.getAttribute( "nickname" ) %></td>
        </tr>
        <tr>
            <td>session attribute</td>
            <td><%= session.getAttribute( "nickname" ) %></td>
        </tr>
        <tr>
            <td>request attribute</td>
            <td><%= request.getAttribute( "nickname" ) %></td>
        </tr>
        <tr>
            <td>pageContext attribute</td>
            <td><%= pageContext.getAttribute( "nickname" ) %></td>
        </tr>
    </table>

    <br><br>

    <table align="center" border="1">
        <tr>
            <td>application attribute</td>
            <td><%= pageContext.getAttribute( "nickname" , PageContext.APPLICATION_SCOPE ) %></td>
        </tr>
        <tr>
            <td>session attribute</td>
            <td><%= pageContext.getAttribute( "nickname" , PageContext.SESSION_SCOPE ) %></td>
        </tr>
        <tr>
            <td>request attribute</td>
            <td><%= pageContext.getAttribute( "nickname" , PageContext.REQUEST_SCOPE ) %></td>
        </tr>
        <tr>
            <td>pageContext attribute</td>
            <td><%= pageContext.getAttribute( "nickname" , PageContext.PAGE_SCOPE ) %></td>
        </tr>
    </table>

    <br><br>

    <p align="center" style="color:blue;"><%= pageContext.findAttribute( "nickname" ) %></p>

    <p align="center" style="color:blue;">${ nickname }</p>

    </body>
</html>
